/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.account.core.repository.entity.BankEntity;
import info.peigen.hotpot.business.account.manage.convertor.BankManageConvertor;
import info.peigen.hotpot.business.account.manage.form.BankManageCreateForm;
import info.peigen.hotpot.business.account.manage.form.BankManageEditForm;
import info.peigen.hotpot.business.account.manage.form.BankManageSearchForm;
import info.peigen.hotpot.business.account.manage.info.BankManageInfo;
import info.peigen.hotpot.business.account.manage.repository.service.BankManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(BankManageService)</b>
 * 管理后台 "银行" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-08-29
 */
@SuppressWarnings("unused")
@Component
public class BankManageService {
    @Inject
    BankManageRepository bankManageRepository;

    public PageResult<BankManageInfo> page(BankManageSearchForm form) {
        LambdaQuery<BankEntity> lambdaQuery = bankManageRepository.getMapper().createLambdaQuery()
                .andLike(BankEntity::getBankId, Query.filterLikeEmpty(form.getBankId(), false, true))
                .andLike(BankEntity::getBankCode, Query.filterLikeEmpty(form.getBankCode(), false, true))
                .andLike(BankEntity::getAccountType, Query.filterLikeEmpty(form.getAccountType(), false, true))
                .andLike(BankEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return bankManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, BankManageConvertor::convertToInfo);
    }

    public void create(BankManageCreateForm form) {
        BankEntity entity = BeanUtil.copyProperties(form, BankEntity.class);
        bankManageRepository.save(entity);
    }

    public void edit(BankManageEditForm form) {
        BankEntity entity = BeanUtil.copyProperties(form, BankEntity.class);
        bankManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        bankManageRepository.delete(id);
    }
}